import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
// import { ValidationPipe } from './pipe/validator.pipe';
import * as express from 'express';
import { ValidationPipe } from './pipe/validator.pipe';
import { TransformInterceptor } from './interceptor/transform.interceptor';
import { HttpReqTransformInterceptor } from './interceptor/http-req.interceptor';
import { AllExceptionsFilter } from './filter/any-exception.filter';
import { HttpExceptionFilter } from './filter/http-exception.filter';
import { Logger } from './utils/log4js';
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.use((req, res, next) => {
    Logger.access(req.url);
    next();
  });
  // 启动cors跨域
  app.enableCors();
  app.use(express.json());

  app.useGlobalPipes(new ValidationPipe());

  // 错误异常捕获 和 过滤处理
  app.useGlobalFilters(new AllExceptionsFilter());
  app.useGlobalFilters(new HttpExceptionFilter()); // 全局统一异常返回体

  app.useGlobalInterceptors(new HttpReqTransformInterceptor<Response>());

  app.useGlobalInterceptors(new TransformInterceptor()); // 全局拦截器，用来收集日志

  await app.listen(3003);
}
bootstrap();
